package com.wsc.personalblog.common;

import com.github.pagehelper.PageInfo;
import com.wsc.personalblog.DTO.ArticleDTO;
import lombok.Data;

import java.util.List;

/**
 * 返回给前端的数据
 */
@Data
public class Result<T> {
    private T data; //成功时返回的数据
    private String message; //失败时返回的信息
    private static final String SUCCESS = "SUCCESS";
    private static final String FAILED = "FAILED";
    private String result;//请求处理是否成功

    public Result(String result , String message , T data){
        this.result=result;
        this.message=message;
        this.data=data;
    }

    /**
     * 请求成功并有数据
     */
    public static <E> Result<E> successHaveData(E data){

        return new Result<E>(SUCCESS,null,data);
    }
    /**
     * 请求成功但无数据
     */
    public static <E> Result<E> successNoData(){
        return new Result<E>(SUCCESS,null,null);
    }
    /**
     * 请求失败
     */
    public static <E> Result<E> failed(String message){
        return new Result<E>(FAILED,message,null);
    }
}
